package com.canxi.games.controller;

import java.util.List;
import java.util.Arrays;

import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.log.dialect.console.ConsoleLog;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.canxi.common.annotation.RepeatSubmit;
import com.canxi.common.annotation.Log;
import com.canxi.common.core.controller.BaseController;
import com.canxi.common.core.domain.PageQuery;
import com.canxi.common.core.domain.R;
import com.canxi.common.core.validate.AddGroup;
import com.canxi.common.core.validate.EditGroup;
import com.canxi.common.enums.BusinessType;
import com.canxi.common.utils.poi.ExcelUtil;
import com.canxi.games.domain.vo.CxGamesVo;
import com.canxi.games.domain.bo.CxGamesBo;
import com.canxi.games.service.ICxGamesService;
import com.canxi.common.core.page.TableDataInfo;

/**
 * 游戏列表
 *
 * @author ruoyi
 * @date 2024-08-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/games/games")
public class CxGamesController extends BaseController {

    private final ICxGamesService iCxGamesService;

    /**
     * 查询游戏列表列表
     */
    @SaCheckPermission("games:games:list")
    @GetMapping("/list")
    public TableDataInfo<CxGamesVo> list(CxGamesBo bo, PageQuery pageQuery) {


        return iCxGamesService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出游戏列表列表
     */
    @SaCheckPermission("games:games:export")
    @Log(title = "游戏列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CxGamesBo bo, HttpServletResponse response) {
        List<CxGamesVo> list = iCxGamesService.queryList(bo);
        ExcelUtil.exportExcel(list, "游戏列表", CxGamesVo.class, response);
    }

    /**
     * 获取游戏列表详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("games:games:query")
    @GetMapping("/{id}")
    public R<CxGamesVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iCxGamesService.queryById(id));
    }

    /**
     * 新增游戏列表
     */
    @SaCheckPermission("games:games:add")
    @Log(title = "游戏列表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CxGamesBo bo) {
        return toAjax(iCxGamesService.insertByBo(bo));
    }

    /**
     * 修改游戏列表
     */
    @SaCheckPermission("games:games:edit")
    @Log(title = "游戏列表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CxGamesBo bo) {
        return toAjax(iCxGamesService.updateByBo(bo));
    }

    /**
     * 删除游戏列表
     *
     * @param ids 主键串
     */
    @SaCheckPermission("games:games:remove")
    @Log(title = "游戏列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iCxGamesService.deleteWithValidByIds(Arrays.asList(ids), true));
    }




}
